//
//  RefreshControl.swift
//  swiftImitationWeibo
//
//  Created by 杨果果 on 16/7/16.
//  Copyright © 2016年 yang. All rights reserved.
//

import UIKit
private let RefreshControlHeight: CGFloat = 50
enum RefreshControlStyle:Int {
    //下拉刷新
    case Normal = 0
    //松手就刷新
    case Pulling = 1
    //正在刷新
    case Refreshing = 2
}
class RefreshControl: UIControl {
    private var refreshState: RefreshControlStyle = .Normal {
        didSet {
//            switch refreshState {
////                print("下拉刷新")
//                
//            }
        }
    }
    //下拉箭头
    private lazy var iconImageView: UIImageView = UIImageView(image: UIImage(named: "tableview_pull_refresh"))
    private var currentScrollView: UIScrollView?
    private lazy var messageLabel: UILabel = {
        let label = UILabel()
        label.text = "下拉刷新"
        label.textColor = UIColor.whiteColor()
        label.font = UIFont.systemFontOfSize(12)
        
    return label
    }()
    //风火轮
    private lazy var indicatorView: UIActivityIndicatorView = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.Gray)
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI() {
        backgroundColor = UIColor.redColor()
        //  添加控件,设置约束
        addSubview(iconImageView)
        addSubview(messageLabel)
        addSubview(indicatorView)
        
        //  使用系统约束进行布局
        //  使用手动布局
        iconImageView.translatesAutoresizingMaskIntoConstraints = false
        
        addConstraint(NSLayoutConstraint(item: iconImageView, attribute: .CenterX, relatedBy: .Equal, toItem: self, attribute: .CenterX, multiplier: 1, constant: -35))
        addConstraint(NSLayoutConstraint(item: iconImageView, attribute: .CenterY, relatedBy: .Equal, toItem: self, attribute: .CenterY, multiplier: 1, constant: 0))
        
        messageLabel.translatesAutoresizingMaskIntoConstraints = false
        addConstraint(NSLayoutConstraint(item: messageLabel, attribute: .Leading, relatedBy: .Equal, toItem: iconImageView, attribute: .Trailing, multiplier: 1, constant: 0))
        addConstraint(NSLayoutConstraint(item: messageLabel, attribute: .CenterY, relatedBy: .Equal, toItem: iconImageView, attribute: .CenterY, multiplier: 1, constant: 0))
        
        indicatorView.translatesAutoresizingMaskIntoConstraints = false
        addConstraint(NSLayoutConstraint(item: indicatorView, attribute: .CenterX, relatedBy: .Equal, toItem: iconImageView, attribute: .CenterX, multiplier: 1, constant: 0))
        addConstraint(NSLayoutConstraint(item: indicatorView, attribute: .CenterY, relatedBy: .Equal, toItem: iconImageView, attribute: .CenterY, multiplier: 1, constant: 0))
    }
    
    
    
    
    
    
    
    
    
    
    
    
}
